<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>绑定class的几种方式</title>
    <style type="text/css">
        .red {
            color: #F00
        }

        .green {
            color: #0F0
        }
    </style>
    <link href="style/demo.css" type="text/css" rel="stylesheet" />
</head>

<body>
    <!-- 对象语法 :class="{'active':isActive,'error':isError}"-->
    <div id="app">
        <div class="red">我是红色</div>
        <div class="green">我是绿色</div>
        <div class="abc" :class="{'active':isActive,'error':isError}">
        </div>


    </div>
    <!-- 数组语法 :class="[activeCls,errorCls]"-->
    <div id="app-2">
        <div :class="[activeCls,errorCls]">
            <p>天降大任</p>
        </div>
        <!-- 三元表达式 -->
        <!-- <div :class="[this.isActive ? activeCls : '',errorCls]"></div> -->
    </div>
    <!-- 条件渲染指令 -->
    <!-- v-if  v-else  v-else -->
    <div id="app-3">
        <p v-if="sex === '男'">你是个男生</p>
        <p v-else-if="sex === '女'">你是个女生</p>
        <p v-else>你既不是个男生也不是个女生</p>

        <template v-if="status === 1">
            <p>这是一个文本</p>
            <p>这是一个文本</p>
            <p>这是一个文本</p>
        </template>

        <template v-if="type === 'name'">
            <label>用户名：</label>
            <input placeholder="输入用户名：" key="name-input">
        </template>
        <template v-else>
            <label>邮箱：</label>
            <input placeholder="输入邮箱：" key="mail-input">
        </template>
        <button @:click="handleToggleClick()">切换输入类型</button>
    </div>
    <!-- 列表渲染指令v-for -->
    <div id="app-4">
        <ul>
            <!-- <li v-for="book in books">{{book.name}}</li>             -->
            <li v-for="(book,index) in books">{{index}}-{{book.name}}</li>
        </ul>
    </div>
    <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                isActive: true,
                isError: false,
                msg: "高歌一首",
            }
        })
        var app2 = new Vue({
            el: "#app-2",
            data: {
                activeCls: 'active',
                errorCls: 'error'
            }
        })

        var app3 = new Vue({
            el: "#app-3",
            data: {
                sex: '男',
                status: 1,
                type: 'name'
            },
            mothods: {
                handleToggleClick: function () {
                    this.type = this.type === 'name' ? 'mail' : 'name';
                }
            }
        })
    </script>
    <script>
        var app4 = new Vue({
            el: "#app-4",
            data: {
                books: [
                    { name: '《斗罗大陆》' },
                    { name: '《斗罗大陆2之绝世唐门》' },
                    { name: '《斗罗大陆3之龙王传说》' },
                    { name: '《斗罗大陆4之终极斗罗》' }
                ]                
            }
        })
    </script>
</body>

</html>